package com.mm.api.config;


import cn.hutool.core.util.StrUtil;
import com.mm.common.utils.SessionHolder;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

/**
 * @BelongsProject: 6.hm-shop
 * @BelongsPackage: com.hmall.api.congif
 * @Author : 游在海里的鱼
 * @CreateTime : 2024-05-07  00:49
 * @Version : 1.0
 * @ClassName : TODO
 * @Description : TODO
 */
public class DefaultFeignConfig {

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 配置日志级别
    **/
    @Bean
    public Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }

    /** ---------------------------------------------------------------------------------------------------------------------
     * @Method  : 用户信息传递，通过请求头
    **/
    @Bean
    public RequestInterceptor userInfoRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                if(StrUtil.isBlank(SessionHolder.getToken())){
                    return;
                }
                requestTemplate.header("session-token", SessionHolder.getToken());
            }
        };
    }
}
